<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="xdz" uri="/xdztools" %>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>list</title>
    <link href="${xdz:domain() }/css/bootstrap.min.css" rel="stylesheet">
    <link href="${xdz:domain() }/css/font-awesome.min.css" rel="stylesheet">
    <link href="${xdz:domain() }/css/animate.min.css" rel="stylesheet">
    <link href="${xdz:domain() }/css/style.min.css" rel="stylesheet">
    <style type="text/css">
    	.tabtree{
    		max-height:500px;
    		overflow-y:scroll; 
    	}
    	.panel{
    		margin-bottom: 0px;
    	}
    </style>
</head>
<body>
	
	

	  <form action="${xdz:domain() }/code/generateBySingleTable" class="form-horizontal" id="generForm" method="post">
			          <div class="panel panel-default">
			          	 <div class="panel-heading">
			          	  	<div class="panel-title"> 
						         	 <i class="fa fa-gear"></i> 代码生成管理
					         </div>
			          	 </div>
			          	 <div class="panel-body">
					         <div class="row">
					     		<div class="col-md-3">
					    				<label class="col-md-4 control-label">设置包类:</label>
				                        <div class="col-md-8">
				                           <input type="text" class="form-control" name="packageName" id="packageName" required="required"/>
				                        </div>
					            </div>
		                       <div class="col-md-3">
					    				<label class="col-md-4 control-label"> <i class="fa fa-search"></i> 选择表:</label>
				                        <div class="col-md-8">
				                            <input name="tablename" class="form-control" readonly="readonly" id="tablename" value="" required="required"/> 
				                        </div>
					            </div>
					            <div class="col-md-3">
					    				<label class="col-md-4 control-label">设置标题:</label>
				                        <div class="col-md-8">
				                            <input name="titleName" class="form-control" id="titleName" value="" required="required" />
				                        </div>
					            </div>
					            <div class="col-md-3 full-right">
					           		 <input type="button" value="生成" id="btn_submit" class="btn btn-info" />
					            </div>
		                	 </div>
	                	 </div>
			     	</div>
		          <div class="panel panel-default">
		          	 <div class="panel-heading">
		          	  	<div class="panel-title"> 
		          	  		<i class="fa fa-table"></i>  数据表:
		          		</div>
		          	</div>
		            <div class="row panel-body text-small">
		              <div class="col-md-3 list-group tabtree" id="tree">
		
		              </div>
					  <div class="col-md-1 list-group" >
					  </div>
	                  <div id="tables">
	
	                  </div>
	               </div>
	          </div>
 	</form>
  <script src="${xdz:domain() }/js/jquery.min.js" type="text/javascript"></script>
  <!-- Bootstrap -->
  <script src="${xdz:domain() }/js/bootstrap.min.js" type="text/javascript"></script>
  <!-- fuelux -->
  <script src="${xdz:domain() }/js/plugins/fuelux/fuelux.js" type="text/javascript"></script>
  <!-- datatables -->
  <script src="${xdz:domain() }/js/plugins/dataTables/jquery.dataTables.js" type="text/javascript"></script>
  <!-- app -->
  <script src="${xdz:domain() }/js/app.js" type="text/javascript"></script>
  <script src="${xdz:domain() }/js/app.plugin.js" type="text/javascript"></script>
  <script src="${xdz:domain() }/js/app.data.js" type="text/javascript"></script>
  <script src="${xdz:domain() }/js/ejs_production.js" type="text/javascript"></script>
  <script src="${xdz:domain() }/js/plugins/layer/layer.min.js" type="text/javascript"></script>
  
  <script type="text/javascript">
  $(document).ready(function(){
	$("#tree")[0].innerHTML='';
	var data="${tables}";
	//alert(data);
	var tableArray = data.split(':');
	for(var i=0;i<tableArray.length;i++){
		$("#tree")[0].innerHTML+="<a class='list-group-item' attr='"+tableArray[i]+"' herf='javascript:void(0)'> <i class='fa fa-table' ></i> "+tableArray[i]+"</a>";
	}
	}) 
  
  </script>
  <script>
      
      $(function(){
          $("#tree").on("click","a",function(){
        	  var tableName=$(this).attr("attr");
        	  $("#tablename").val(tableName);
        	  var tis=$(this);
        	  $.ajax({
    				url : "../code/getCoulmnsList?_rnd="+Math.random(10000000000),
    				type : 'POST',
    				data : {"tableName":tableName},
    				dataType:"text",
    				success : function(d) {    					
    					var data=JSON.parse(d);
    					data.supplies=data.supplies.split(",");
    			              if(tis.attr("data-c")){
    			                  if($("."+data.table).length==1){
    			                	  $("#tablename").val("");
    			                    //显示则隐藏 否则显示
    			                      $("."+data.table).remove();
    			                      tis.attr("data-c",0);
    			                  }else{
    			                	  tis.attr("data-c",1);
    			                      html = new EJS({url: '../js/template/list.ejs'}).render(data);
    			                      $("#tables").html(html);
    			                  }

    			              }else{
    			            	  tis.attr("data-c",1);
    			                  html = new EJS({url: '../js/template/list.ejs'}).render(data);
    			                  $("#tables").html(html);
    			              }

    					}
    			});
              
              return false;
          })
          
          $("#btn_submit").click(function(){
        	  if(document.getElementById("packageName").value.length<=0){
        		  layer.alert("包类不可以为空！");
	      			return false;
	      		}
	      		
	      		if(document.getElementById("tablename").value.length<=0){
	      			layer.alert("必须选择一张表！");
	      			return false;
	      		}
	      		
	      		if(document.getElementById("titleName").value.length<=0){
	      			layer.alert("请设置展示标题！");
	      			return false;
	      		}
	      		
	      		
	      		$.ajax({
	  			   type: "POST",
	  			   url: "../code/generateBySingleTable?_rnd="+Math.random(10000000000),
	  			   data: $('#generForm').serialize(),
	  			   success: function(msg){
	  			     layer.alert("生成文件结果: " + msg );
	  			   }
	  			});
          });
      })
      
  </script>
  
</body>
</html>